{include file="public/header"}
<!-- 列表 -->
<style>
    .layui-table img {
        max-width: none;
    }
</style>
</head>

<body>
    <div class="cBody">
        <div class="console">
            <a class="layui-btn" onclick="OpenView('{:url('AdminRole/add')}','添加角色')">添加角色</a>
            <div class="layui-form-item" style="float: right;">
                <div class="layui-input-inline">
                    <input type="text" name="name" placeholder="角色名称" id="name" class="layui-input ">
                </div>
                <button class="layui-btn" id="do_search">检索</button>
            </div>
        </div>
        <table class="layui-table" id="demo" lay-filter="test">
            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="ability">设置权限</a>
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
            </script>
        </table>

    </div>
</body>
<script>
    layui.use(['table', 'layer'], function () {
        var table = layui.table;
        var layer = layui.layer;
        //第一个实例
        var datatable = table.render({
            elem: '#demo'
            , url: '{:url('AdminRole/list')}' //数据接口
            , method: 'POST'
            , cols: [[ //表头
                { field: 'name', title: '角色名称', sort: true },
                { field: 'add_date', title: '创建时间', sort: true, templet: '<div>{{ layui.laytpl.toDateString(d.add_date*1000) }}</div>' },
                { field: 'rep_date', title: '更新时间', sort: true, templet: '<div>{{ layui.laytpl.toDateString(d.rep_date*1000) }}</div>' },
                { field: 'desc', title: '角色描述', sort: false },
                { field: 'right', title: '操作', toolbar: "#barDemo", fixed: 'right' }
            ]]
            , page: true
        });
        //监听工具条
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                // console.log(data.id);
                del('{:url('AdminRole/del')}', data.id, obj);
            } else if (obj.event === 'edit') {
                OpenView('{:url('AdminRole/edit')}?id=' + data.id, '编辑角色');
            } else if (obj.event === 'ability') {
                OpenView('{:url('AdminRole/ability')}?id=' + data.id, '设置权限');
            }
        });
        // 执行搜索，表格重载
        $('#do_search').on('click', function () {
            // 搜索条件
            var name = $('#name').val();
            table.reload('demo', {
                method: 'post'
                , where: {
                    'name': name,
                }
                , page: true
            });
        });
    });
</script>
{include file="public/footer"}